package org.dfl.plugin.editor.parts;

import org.dfl.plugin.editor.figures.FiguresConstants;
import org.dfl.plugin.editor.figures.TransitionFigure;
import org.dfl.plugin.editor.model.TransitionModelElement;
import org.eclipse.draw2d.IFigure;


/**
 * EditPart used for Transition instances
 * <p>
 * This edit part must implement the PropertyChangeListener interface, so it can
 * be notified of property changes in the corresponding model element.
 * </p>
 * 
 * @author Piotr Wlodarczyk
 */
class TransitionEditPart extends ShapeEditPart {
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	protected IFigure createFigure() {
		TransitionFigure f = new TransitionFigure(getCastedModel().getLabelText(),getCastedModel().getTipText());
		f.setOpaque(true); // non-transparent figure
		refreshFigure(f);
		return f;
	}

	protected TransitionModelElement getCastedModel() {
		return (TransitionModelElement) getModel();
	}
	
	protected void refreshFigure(IFigure ff){
		TransitionFigure f = (TransitionFigure) ff;
		f.setLabelText(getCastedModel().getLabelText());
		f.setTipText(getCastedModel().getTipText());
		
		if(getCastedModel().isRunning()){
			f.setBackgroundColor(FiguresConstants.transitionColorRun);	
		}else if(getCastedModel().getTransition().areAllInputsDefined()){
			f.setBackgroundColor(FiguresConstants.transitionColorStop);
		}else{
			f.setBackgroundColor(FiguresConstants.transitionColorNotDefined);
		}
		
	}
}